<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../0js/vue.js"></script>
</head>
<body>

<div id="root">
    <h2>今天天气很好{{info}}, {{i}}</h2>
    <button @click="changeWeather">切换天气</button>
    <!--    <button @click="isHot = !isHot">切换天气</button>-->

    <hr>

    <h3>a的值是: {{numbers.a}}</h3>
    <button @click="numbers.a++">点我a+1</button>
    <br>
    <h3>a的值是: {{numbers.b}}</h3>
    <button @click="numbers.b++">点我b+1</button>
</div>

<script type="text/javascript">
    // 阻止vue在启动时生成生产提示
    Vue.config.productionTip = false

    // 定时器回调， ajax回调，Promise回调，最好是➡箭头函数， 如果是funciton (){} this就会是window
    const vm = new Vue({
        el: "#root",
        data: {
            isHot: true,
            i: 0,
            numbers: {
                a:1,
                b:1
            }
        },
        computed: {
            info() {
                return this.isHot ? "炎热" : "凉爽"
            }
        },
        methods: {
            changeWeather() {
                this.isHot = !this.isHot
                this.i++

                /*let function1 = new Function("return !vm.isHot");

                console.log(function1())*/
            }
        },
        watch: { // 深度监视，默认vue不开启， 属性默认是监视深度
            isHot: {
                handler(newValue, oldValue) {
                    console.log("isHot被修改了")
                }
            },
            numbers : {
                deep: true, // 深度监视
                handler(newValue, oldValue) {
                    console.log("numbers.a修改了")
                }
            },
            // 简写
            /*isHot(newValue, oldValue) {
                console.log("isHot被修改了")
            }*/
        }
    });

</script>
</body>
</html>